﻿#region Using namespaces

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using BOL.Utils.SurvivalAnalysis;

#endregion

namespace BOL.Apps.GeneNetworkBrowser.Analysis.Survival
{
    public class SubNetworkCoxRegression : CoxRegression, IAnalysis
    {
        #region Constructors

        public SubNetworkCoxRegression(double alpha, IEnumerable<Network> subNetworks, string[] ids, double[] times, int[] endPoints)
            : base(alpha, GetVariates(subNetworks, ids), times, endPoints)
        {
            this._name = String.Format("SubNetwork Cox regression}");
        }

        private static double[][] GetVariates(IEnumerable<Network> subNetworks, string[] ids)
        {
            int p = subNetworks.Count();
            int n = ids.Length;

            var X = new double[n][];
            for (int i = 0; i < n; i++)
                X[i] = subNetworks.Select(network => network.Activity(ids[i])).ToArray();

            return X;
        }

        #endregion

        #region IAnalysis implementation

        private string _name;

        public string Name { get { return _name; } set { _name = value; } }

        public IResult Analyze()
        {
            return new SubNetworkCoxRegressionResult(String.Format("Result: {0}", _name), this);
        }

        #endregion
    }
}
